package UI;

import Service.SecurityData;
import facecat.topin.core.*;
import facecat.topin.grid.*;
import facecat.topin.chart.*;
import facecat.topin.div.*;
import facecat.topin.btn.*;
import java.util.*;
import java.text.*;
import java.io.*;
import java.net.*;
import org.w3c.dom.Node;

public class MainFrame2 extends UIXmlEx implements FCPaintEventCallBack, FCGridCellTouchEventCallBack, FCTouchEventCallBack{
    public String m_latestDataStr = "";

    public FCGrid m_gridStocks;

    public HashMap<FCView, HashMap<String, String>> m_myChartsMap = new HashMap<FCView, HashMap<String, String>>();

    public ArrayList<FCChart> m_charts = new ArrayList<FCChart>();

    public ArrayList<FCView> m_findMyCharts = new ArrayList<FCView>();

    /*
    * 根据名称查找视图
    */
    public void findViewsByType(String findType, ArrayList<FCView> views, ArrayList<FCView> refViews)
    {
        for (int i = 0; i < views.size(); i++)
        {
            FCView view = views.get(i);
            if (m_myChartsMap.containsKey(view))
            {
                refViews.add(view);
            }
            else
            {
                findViewsByType(findType, view.getViews(), refViews);
            }
        }
    }

    /*
    * 获取价格颜色
    */
    public long getPriceColor(double price, double comparePrice)
    {
        if (price != 0)
        {
            if (price > comparePrice)
            {
                return FCColor.rgb(255, 82, 82);
            }
            else if (price < comparePrice)
            {
                return FCColor.rgb(46, 255, 50);
            }
        }
        return FCColor.rgb(190, 190, 235);
    }

    /*
    * 创建单元格
    */
    public FCGridCell createGridCell(FCGrid grid)
    {
        FCGridCell gridCell = new FCGridStringCell();
        FCGridCellStyle cellStyle = new FCGridCellStyle();
        if (MyColor.getStyle() == 0)
        {
            cellStyle.setBackColor(FCColor.None);
            cellStyle.setTextColor(FCColor.rgb(175, 196, 228));
        }
        else if (MyColor.getStyle() == 1)
        {
            cellStyle.setBackColor(FCColor.None);
            cellStyle.setTextColor(FCColor.rgb(0, 0, 0));
        }
        cellStyle.setFont(new FCFont("Default", 13));
        gridCell.setStyle(cellStyle);
        return gridCell;
    }
    
    /*
    * 请求数据
    */
    public ArrayList<String> get(String url){
        ArrayList<String> strs = new ArrayList<String>();
        try{
            URL obj = new URL(url);
            HttpURLConnection con = (HttpURLConnection) obj.openConnection();
            con.setRequestMethod("GET");
            BufferedReader in = new BufferedReader(new InputStreamReader(con.getInputStream()));
            String inputLine;
            while ((inputLine = in.readLine()) != null) {
                strs.add(inputLine);
            }
            in.close();
        }catch(Exception ex){

        }
        return strs;
    }
    
    /*
    * 黑色风格
    */
    public void toBlackChart(FCChart chart, int index)
    {
        chart.setBackColor(FCColor.Back);
        chart.setBorderColor(FCColor.None);
        chart.setTextColor(FCColor.rgb(175, 196, 228));
        chart.m_scaleColor = FCColor.rgb(75, 75, 75);
        chart.m_crossTipColor = FCColor.rgb(50, 50, 50);
        chart.m_crossLineColor = FCColor.rgb(100, 100, 100);
        chart.m_gridColor = FCColor.rgb(50, 50, 50);
        if (index > 0)
        {
            chart.m_upColor = FCColor.rgb(186, 56, 18);
            chart.m_downColor = FCColor.rgb(31, 182, 177);
        }
        else
        {
            chart.m_upColor = FCColor.rgb(255, 82, 82);
            chart.m_downColor = FCColor.rgb(46, 255, 50);
        }
        chart.m_barStyle = "rect2";
        chart.m_candleStyle = "rect2";
        chart.m_trendColor = FCColor.rgb(255, 255, 255);
        chart.m_hScaleTextColor = FCColor.rgb(194, 151, 18);
        chart.m_vScaleTextColor = FCColor.rgb(194, 151, 18);
    }
    
    /*
    * 加载Xml
    */
    public void loadXml(String xmlPath, FCView parent)
    {
        super.loadXml(xmlPath, null);
        getNative().findView("divLatest").addEvent(this, FCEventID.Paint, this);
        m_gridStocks = (FCGrid)getNative().findView("gridStocks");
        for (int i = 3; i < m_gridStocks.m_columns.size(); i++)
        {
            m_gridStocks.getColumn(i).setCellAlign(FCHorizontalAlign.Right);
        }
        m_gridStocks.getRowStyle().setSelectedBackColor(FCColor.rgb(75, 75, 75));
        m_gridStocks.getRowStyle().setHoveredBackColor(FCColor.None);
        m_gridStocks.addEvent(this, FCEventID.GridCellClick, this);
        queryPrice("all");
        String strCode = "600000.SH";
        String strName = "浦发银行";
        findViewsByType("mychart", getNative().getViews(), m_findMyCharts);
        for (int i = 0; i < m_findMyCharts.size(); i++)
        {
            FCView myChart = m_findMyCharts.get(i);
            FCSplitLayoutDiv splitDiv = new FCSplitLayoutDiv();
            splitDiv.setLayoutStyle(FCLayoutStyle.TopToBottom);
            splitDiv.setSize(new FCSize(400, 400));
            splitDiv.setBackColor(FCColor.None);
            splitDiv.setBorderColor(FCColor.None);
            splitDiv.setDock(FCDockStyle.Fill);
            myChart.addView(splitDiv);

            FCLayoutDiv topDiv = new FCLayoutDiv();
            topDiv.setBackColor(FCColor.None);
            topDiv.setBorderColor(FCColor.None);
            topDiv.setLayoutStyle(FCLayoutStyle.LeftToRight);
            topDiv.setShowHScrollBar(false);
            splitDiv.addView(topDiv);

            FCDiv bottomDiv = new FCDiv();
            bottomDiv.setBackColor(FCColor.None);
            bottomDiv.setBorderColor(FCColor.None);
            splitDiv.addView(bottomDiv);

            splitDiv.setFirstView(topDiv);
            splitDiv.setSecondView(bottomDiv);

            FCView splitter = splitDiv.getSplitter();
            splitter.setSize(new FCSize(400, 1));
            splitter.setLocation(new FCPoint(0, 30));
            if (i == 0)
            {
                splitter.setLocation(new FCPoint(0, 0));
            }
            FCChart chart = new FCChart();
            chart.m_leftVScaleWidth = 70;
            chart.m_rightVScaleWidth = 70;
            if (i > 0){
			    chart.m_leftVScaleWidth = 0;
		    }
            chart.m_vScaleDistance = 35;
            chart.m_hScalePixel = 11;
            chart.m_hScaleHeight = 30;
            chart.m_candlePaddingTop = 30;
            chart.m_candlePaddingBottom = 20;
            chart.m_volPaddingTop = 20;
            chart.m_volPaddingBottom = 0;
            chart.m_vScaleDistance = 35;
            chart.setDock(FCDockStyle.Fill);
            chart.setFont(new FCFont("Default", 12));
            chart.m_candleDivPercent = FCTran.strToDouble(m_myChartsMap.get(myChart).get("candledivpercent"));
            chart.m_volDivPercent = FCTran.strToDouble(m_myChartsMap.get(myChart).get("voldivpercent"));
            chart.m_indDivPercent = 0;
            String text = strCode + " " + strName;
            int intCycle = FCTran.strToInt(m_myChartsMap.get(myChart).get("cycle"));
            if (intCycle == 0)
            {
                text += " 分时";
            }
            else if (intCycle < 1440)
            {
                text += " " + FCTran.intToStr(intCycle) + "分钟";
            }
            else if (intCycle == 1440)
            {
                text += " 日线";
            }
            else if (intCycle == 10080)
            {
                text += " 周线";
            }
            else if (intCycle == 43200)
            {
                text += " 月线";
            }
            chart.setText(text);
            chart.m_allowDragChartDiv = true;
            m_charts.add(chart);
            bottomDiv.addView(chart);
            toBlackChart(chart, intCycle);
            queryHistoryData(myChart, chart, strCode);

            ArrayList<String> cycles = new ArrayList<String>();
            cycles.add("1");
            cycles.add("5");
            cycles.add("10");
            cycles.add("15");
            cycles.add("20");
            cycles.add("30");
            cycles.add("60");
            cycles.add("90");
            cycles.add("120");
            cycles.add("日");
            cycles.add("周");
            cycles.add("月");
            cycles.add("季");
            cycles.add("半");
            cycles.add("年");
            ArrayList<Integer> cyclesInts = new ArrayList<Integer>();
            cyclesInts.add(1);
            cyclesInts.add(5);
            cyclesInts.add(10);
            cyclesInts.add(15);
            cyclesInts.add(20);
            cyclesInts.add(30);
            cyclesInts.add(60);
            cyclesInts.add(90);
            cyclesInts.add(120);
            cyclesInts.add(1440);
            cyclesInts.add(10080);
            cyclesInts.add(43200);
            cyclesInts.add(129600);
            cyclesInts.add(259200);
            cyclesInts.add(518400);
            for (int c = 0; c < cycles.size(); c++)
            {
                FCButton cycleButton = new FCButton();
                cycleButton.setText(cycles.get(c));
                cycleButton.setSize(new FCSize(27, 30));
                cycleButton.setTextColor(FCColor.rgb(200, 200, 200));
                cycleButton.setBorderColor(FCColor.rgb(50, 50, 50));
                cycleButton.setBackColor(FCColor.None);
                cycleButton.setName("cycle," + FCTran.intToStr(i) + "," + FCTran.intToStr(cyclesInts.get(c)));
                topDiv.addView(cycleButton);
                cycleButton.addEvent(this, FCEventID.Click, this);
            }
        }
        queryNewData(strCode);
    }
    
    /*
    * 创建视图
    */
    public FCView createView(Node node, String type)
    {
        if (type.equals("mychart"))
        {
            FCView myChart = new FCView();
            HashMap<String, String> attributes = getAttributes(node);
            m_myChartsMap.put(myChart, attributes);
            return myChart;
        }
        else if (type.equals("latestdiv"))
        {
            return new FCView();
        }
        else if (type.equals("securitylist"))
        {
            return new FCGrid();
        }
        else
        {
            return super.createView(node, type);
        }
    }

    /*
    * 绘图事件
    */
    public boolean callPaintEvent(String eventName, Object sender, FCPaint paint, FCRect clipRect, Object invoke)
    {
        FCView view = (FCView)sender;
        if(m_charts.size() == 0){
            return false;
        }
        int avgHeight = 20;
        FCFont drawFont = new FCFont("Default", 14);
        int dTop = 30;
        paint.drawLine(view.getBorderColor(), 1, 0, 0, dTop, view.getSize().cx, dTop);
        String[] dataStrs = m_latestDataStr.split("[,]");
        double lastClose = 0;
        ArrayList<Double> priceList = new ArrayList<Double>();
        ArrayList<Double> volList = new ArrayList<Double>();
        ArrayList<String> buySellTexts = new ArrayList<String>();
        if (dataStrs.length > 10)
        {
            FCDraw.drawText(paint, dataStrs[0], FCColor.rgb(175, 196, 228), new FCFont("Default", 14), 5, 7);
            FCDraw.drawText(paint, dataStrs[1], FCColor.rgb(194, 151, 18), new FCFont("Default", 14), 80, 7);
            lastClose = FCTran.strToDouble(dataStrs[8]);
            priceList.add(FCTran.strToDouble(dataStrs[23]));
            priceList.add(FCTran.strToDouble(dataStrs[22]));
            priceList.add(FCTran.strToDouble(dataStrs[21]));
            priceList.add(FCTran.strToDouble(dataStrs[20]));
            priceList.add(FCTran.strToDouble(dataStrs[19]));
            priceList.add(FCTran.strToDouble(dataStrs[9]));
            priceList.add(FCTran.strToDouble(dataStrs[10]));
            priceList.add(FCTran.strToDouble(dataStrs[11]));
            priceList.add(FCTran.strToDouble(dataStrs[12]));
            priceList.add(FCTran.strToDouble(dataStrs[13]));

            volList.add(FCTran.strToDouble(dataStrs[28]));
            volList.add(FCTran.strToDouble(dataStrs[27]));
            volList.add(FCTran.strToDouble(dataStrs[26]));
            volList.add(FCTran.strToDouble(dataStrs[25]));
            volList.add(FCTran.strToDouble(dataStrs[24]));
            volList.add(FCTran.strToDouble(dataStrs[14]));
            volList.add(FCTran.strToDouble(dataStrs[15]));
            volList.add(FCTran.strToDouble(dataStrs[16]));
            volList.add(FCTran.strToDouble(dataStrs[17]));
            volList.add(FCTran.strToDouble(dataStrs[18]));
        }
        buySellTexts.add("卖5");
        buySellTexts.add("卖4");
        buySellTexts.add("卖3");
        buySellTexts.add("卖2");
        buySellTexts.add("卖1");
        buySellTexts.add("买1");
        buySellTexts.add("买2");
        buySellTexts.add("买3");
        buySellTexts.add("买4");
        buySellTexts.add("买5");
        long textColor = FCColor.rgb(175, 196, 228);
        if (MyColor.getStyle() == 1)
        {
            textColor = FCColor.rgb(0, 0, 0);
        }
        double maxVol = m_charts.get(0).maxValue(volList);
        for (int i = 0; i < 10; i++)
        {
            FCSize tSize = paint.textSize(buySellTexts.get(i), drawFont);
            FCDraw.drawText(paint, buySellTexts.get(i), textColor, drawFont, 5, dTop + avgHeight / 2 - tSize.cy / 2);
            if (priceList.size() > 0)
            {
                double price = priceList.get(i);
                long upDownColor = FCColor.rgb(255, 82, 82);
                long upDownColor2 = FCColor.rgba(255, 82, 82, 50);
                if (price < lastClose)
                {
                    upDownColor = FCColor.rgb(46, 255, 50);
                    upDownColor2 = FCColor.rgba(46, 255, 50, 50);
                }
                FCDraw.drawText(paint, FCTran.getValueByDigit(priceList.get(i), 2), upDownColor, drawFont, 50, dTop + avgHeight / 2 - tSize.cy / 2);
                if (maxVol > 0)
                {
                    paint.fillRect(upDownColor2, view.getSize().cx - (int)(volList.get(i) * 80 / maxVol), dTop + 2, view.getSize().cx, dTop + avgHeight - 2);
                }
                String volText = FCTran.getValueByDigit(volList.get(i) / 100, 0);
                FCSize volTextSize = paint.textSize(volText, drawFont);
                FCDraw.drawText(paint, volText, textColor, drawFont, view.getSize().cx - volTextSize.cx - 10, dTop + avgHeight / 2 - volTextSize.cy / 2);
            }
            dTop += avgHeight;
        }
        paint.drawLine(view.getBorderColor(), 1, 0, 0, dTop, view.getSize().cx, dTop);
        FCDraw.drawText(paint, "现价", FCColor.rgb(175, 196, 228), drawFont, 5, dTop + 10);
        FCDraw.drawText(paint, "幅度", FCColor.rgb(175, 196, 228), drawFont, 5, dTop + 35);
        FCDraw.drawText(paint, "总额", FCColor.rgb(175, 196, 228), drawFont, 5, dTop + 60);
        FCDraw.drawText(paint, "总量", FCColor.rgb(175, 196, 228), drawFont, 5, dTop + 85);
        FCDraw.drawText(paint, "开盘", FCColor.rgb(175, 196, 228), drawFont, 110, dTop + 10);
        FCDraw.drawText(paint, "振幅", FCColor.rgb(175, 196, 228), drawFont, 110, dTop + 35);
        FCDraw.drawText(paint, "最高", FCColor.rgb(175, 196, 228), drawFont, 110, dTop + 60);
        FCDraw.drawText(paint, "最低", FCColor.rgb(175, 196, 228), drawFont, 110, dTop + 85);
        if (dataStrs.length > 10)
        {
            double close = FCTran.strToDouble(dataStrs[2]);
            double high = FCTran.strToDouble(dataStrs[3]);
            double low = FCTran.strToDouble(dataStrs[4]);
            double open = FCTran.strToDouble(dataStrs[5]);
            double volume = FCTran.strToDouble(dataStrs[6]);
            double amount = FCTran.strToDouble(dataStrs[7]);
            double diff = 0;
            if (lastClose > 0)
            {
                diff = 100 * (close - lastClose) / lastClose;
            }

            double diff2 = 0;
            if (lastClose > 0)
            {
                diff2 = 100 * (high - lastClose) / lastClose - 100 * (low - lastClose) / lastClose;
            }
            FCDraw.drawText(paint, FCTran.getValueByDigit(close, 2), getPriceColor(close, lastClose), drawFont, 40, dTop + 10);
            FCDraw.drawText(paint, FCTran.getValueByDigit(diff, 2) + "%", getPriceColor(close, lastClose), drawFont, 40, dTop + 35);
            FCDraw.drawText(paint, FCTran.getValueByDigit(amount / 10000, 0), textColor, drawFont, 40, dTop + 60);
            FCDraw.drawText(paint, FCTran.getValueByDigit(volume / 10000, 0), textColor, drawFont, 40, dTop + 85);

            FCDraw.drawText(paint, FCTran.getValueByDigit(open, 2), getPriceColor(open, lastClose), drawFont, 150, dTop + 10);
            FCDraw.drawText(paint, FCTran.getValueByDigit(diff2, 2) + "%", getPriceColor(close, lastClose), drawFont, 150, dTop + 35);
            FCDraw.drawText(paint, FCTran.getValueByDigit(high, 2), getPriceColor(high, lastClose), drawFont, 150, dTop + 60);
            FCDraw.drawText(paint, FCTran.getValueByDigit(low, 2), getPriceColor(low, lastClose), drawFont, 150, dTop + 85);
        }
        return true;
    }

    /*
    * 请求报价数据
    */
    public void queryPrice(String codes)
    {
        String url = "http://110.42.188.197:9968/quote?func=price&count=500&codes=" + codes;
        ArrayList<String> strs = get(url);
        m_gridStocks.beginUpdate();
        for (int i = 0; i < strs.size(); i++)
        {
            String[] subStrs = strs.get(i).split("[,]");
            if (subStrs.length >= 15)
            {
                FCGridRow row = new FCGridRow();
                row.setHeight(30);
                m_gridStocks.addRow(row);
                FCGridCell cell1 = createGridCell(m_gridStocks);
                cell1.setText(FCTran.intToStr(i));
                row.addCell(0, cell1);

                FCGridCell cell2 = createGridCell(m_gridStocks);
                cell2.setText(subStrs[0]);
                cell2.getStyle().setTextColor(FCColor.rgb(194, 151, 18));
                row.addCell(1, cell2);

                FCGridCell cell3 = createGridCell(m_gridStocks);
                cell3.setText(subStrs[1]);
                row.addCell(2, cell3);

                double close = FCTran.strToDouble(subStrs[2]);
                double high = FCTran.strToDouble(subStrs[3]);
                double low = FCTran.strToDouble(subStrs[4]);
                double lastClose = FCTran.strToDouble(subStrs[8]);
                FCGridCell cell4 = createGridCell(m_gridStocks);
                cell4.setText(FCTran.getValueByDigit(close, 2));
                cell4.getStyle().setTextColor(getPriceColor(close, lastClose));
                row.addCell(3, cell4);

                double diff = 0;
                if (lastClose > 0)
                {
                    diff = 100 * (close - lastClose) / lastClose;
                }
                FCGridCell cell5 = createGridCell(m_gridStocks);
                cell5.setText(FCTran.getValueByDigit(diff, 2) + "%");
                cell5.getStyle().setTextColor(getPriceColor(diff, 0));
                row.addCell(4, cell5);

                FCGridCell cell6 = createGridCell(m_gridStocks);
                cell6.setText(FCTran.getValueByDigit(close - lastClose, 2));
                cell6.getStyle().setTextColor(getPriceColor(close, lastClose));
                row.addCell(5, cell6);

                double volume = FCTran.strToDouble(subStrs[6]);
                double amount = FCTran.strToDouble(subStrs[7]);
                FCGridCell cell7 = createGridCell(m_gridStocks);
                cell7.setText(FCTran.getValueByDigit(volume / 100 / 10000, 2) + "万");
                row.addCell(6, cell7);

                FCGridCell cell8 = createGridCell(m_gridStocks);
                cell8.setText(FCTran.getValueByDigit(amount / 100000000, 2) + "亿");
                row.addCell(7, cell8);

                FCGridCell cell9 = createGridCell(m_gridStocks);
                cell9.setText(FCTran.getValueByDigit(FCTran.strToDouble(subStrs[12]), 2));
                row.addCell(8, cell9);

                FCGridCell cell10 = createGridCell(m_gridStocks);
                cell10.setText(FCTran.getValueByDigit(FCTran.strToDouble(subStrs[11]), 2));
                row.addCell(9, cell10);

                double diff2 = 0;
                if (lastClose > 0)
                {
                    diff2 = 100 * (high - lastClose) / lastClose - 100 * (low - lastClose) / lastClose;
                }
                FCGridCell cell11 = createGridCell(m_gridStocks);
                cell11.setText(FCTran.getValueByDigit(diff2, 2) + "%");
                row.addCell(10, cell11);

                FCGridCell cell12 = createGridCell(m_gridStocks);
                cell12.setText(FCTran.getValueByDigit(FCTran.strToDouble(subStrs[13]), 2));
                row.addCell(11, cell12);

                double marketValue = FCTran.strToDouble(subStrs[9]) * close;
                FCGridCell cell13 = createGridCell(m_gridStocks);
                cell13.setText(FCTran.getValueByDigit(marketValue / 100000000, 2) + "亿");
                row.addCell(12, cell13);

                double flowValue = FCTran.strToDouble(subStrs[10]) * close;
                FCGridCell cell14 = createGridCell(m_gridStocks);
                cell14.setText(FCTran.getValueByDigit(flowValue / 100000000, 2) + "亿");
                row.addCell(13, cell14);

                FCGridCell cell15 = createGridCell(m_gridStocks);
                cell15.setText("");
                row.addCell(14, cell15);

                double upperLimit = FCTran.strToDouble(subStrs[14]);
                double lowerLimit = FCTran.strToDouble(subStrs[15]);
                FCGridCell cell16 = createGridCell(m_gridStocks);
                cell16.setText(FCTran.getValueByDigit(upperLimit, 2));
                cell16.getStyle().setTextColor(getPriceColor(1, 0));
                row.addCell(15, cell16);

                FCGridCell cell17 = createGridCell(m_gridStocks);
                cell17.setText(FCTran.getValueByDigit(lowerLimit, 2));
                cell17.getStyle().setTextColor(getPriceColor(0, 1));
                row.addCell(16, cell17);

                FCGridCell cell18 = createGridCell(m_gridStocks);
                cell18.setText("");
                row.addCell(17, cell18);

                FCGridCell cell19 = createGridCell(m_gridStocks);
                cell19.setText("");
                row.addCell(18, cell19);

                FCGridCell cell20 = createGridCell(m_gridStocks);
                cell20.setText("");
                row.addCell(19, cell20);

                FCGridCell cell21 = createGridCell(m_gridStocks);
                cell21.setText("");
                row.addCell(20, cell21);

                FCGridCell cell22 = createGridCell(m_gridStocks);
                cell22.setText("");
                row.addCell(21, cell22);
            }
        }
        m_gridStocks.endUpdate();
        m_gridStocks.invalidate();
    }

    /*
    * 请求最新数据
    */
    public void queryNewData(String code)
    {
        String url = "http://110.42.188.197:9968/quote?func=getnewdata&codes=" + code;
        m_latestDataStr = get(url).get(0);
        getNative().invalidate();
    }

    /*
    * 请求历史数据
    */
    public void queryHistoryData(FCView mychart, FCChart chart, String code)
    {
        String strCycle = m_myChartsMap.get(mychart).get("cycle");
        int intCycle = FCTran.strToInt(strCycle);
        String url = "http://110.42.188.197:9968/quote?func=getkline&code=" + code + "&cycle=" + strCycle + "&count=500";
        if (intCycle == 0)
        {
            url = "http://110.42.188.197:9968/quote?func=getkline&code=" + code + "&cycle=0&count=240";
        }
        ArrayList<String> strs = get(url);
        ArrayList<SecurityData> dataList = new ArrayList<SecurityData>();
        chart.m_firstOpen = 0;
        if (intCycle == 0)
        {
            String []fStrs = strs.get(0).split("[ ]");
            if (fStrs.length >= 3)
            {
                chart.m_firstOpen = FCTran.strToDouble(fStrs[2]);
            }
        }
        for (int i = 2; i < strs.size(); i++)
        {
            String []subStrs = strs.get(i).split("[,]");
            if (subStrs.length >= 7)
            {
                SecurityData data = new SecurityData();
                if (intCycle < 1440)
                {
                    int year = FCTran.strToInt(subStrs[0].substring(0, 4));
                    String strMonth = subStrs[0].substring(5, 7);
                    int month = FCTran.strToInt(strMonth);
                    if(strMonth.indexOf("0") == 0){
                        month = FCTran.strToInt(strMonth.substring(1));
                    }
                    String strDay = subStrs[0].substring(8, 10);
                    int day = FCTran.strToInt(strDay);
                    if(strDay.indexOf("0") == 0){
                        day = FCTran.strToInt(strDay.substring(1));
                    }
                    String strHour = subStrs[1].substring(0, 2);
                    int hour = FCTran.strToInt(strHour);
                    if(strHour.indexOf("0") == 0){
                        hour = FCTran.strToInt(strHour.substring(1));
                    }
                    String strMinute = subStrs[1].substring(2, 4);
                    int minute = FCTran.strToInt(strMinute);
                    if(strMinute.indexOf("0") == 0){
                        minute = FCTran.strToInt(strHour.substring(1));
                    }
                    data.m_open = FCTran.strToDouble(subStrs[2]);
                    data.m_high = FCTran.strToDouble(subStrs[3]);
                    data.m_low = FCTran.strToDouble(subStrs[4]);
                    data.m_close = FCTran.strToDouble(subStrs[5]);
                    data.m_volume = FCTran.strToDouble(subStrs[6]);
                    data.m_date = FCTran.getDateNum(year, month, day, hour, minute, 0, 0);
                    if (intCycle == 0 && (data.m_volume > 0 || dataList.size() == 0))
                    {
                        chart.m_lastValidIndex = dataList.size();
                        if (chart.m_firstOpen == 0)
                        {
                            chart.m_firstOpen = data.m_close;
                        }
                    }
                }
                else
                {
                    int year = FCTran.strToInt(subStrs[0].substring(0, 4));
                    String strMonth = subStrs[0].substring(5, 7);
                    int month = FCTran.strToInt(strMonth);
                    if(strMonth.indexOf("0") == 0){
                        month = FCTran.strToInt(strMonth.substring(1));
                    }
                    String strDay = subStrs[0].substring(8, 10);
                    int day = FCTran.strToInt(strDay);
                    if(strDay.indexOf("0") == 0){
                        day = FCTran.strToInt(strDay.substring(1));
                    }
                    data.m_open = FCTran.strToDouble(subStrs[1]);
                    data.m_high = FCTran.strToDouble(subStrs[2]);
                    data.m_low = FCTran.strToDouble(subStrs[3]);
                    data.m_close = FCTran.strToDouble(subStrs[4]);
                    data.m_volume = FCTran.strToDouble(subStrs[5]);
                    data.m_date = FCTran.getDateNum(year, month, day, 0, 0, 0, 0);
                }
                dataList.add(data);
            }
        }
        if (intCycle == 0)
        {
            chart.m_autoFillHScale = true;
            chart.m_cycle = "trend";
        }
        else if (intCycle < 1440)
        {
            chart.m_cycle = "minute";
        }
        else
        {
            chart.m_cycle = "day";
        }
        chart.m_datas = dataList;
        int maxVisibleRecord = chart.getChartMaxVisibleCount(chart.m_hScalePixel, chart.getChartWorkAreaWidth());
        chart.m_lastVisibleIndex = chart.m_datas.size() - 1;
        if (maxVisibleRecord > chart.m_datas.size())
        {
            chart.m_firstVisibleIndex = 0;
        }
        else
        {
            chart.m_firstVisibleIndex = chart.m_lastVisibleIndex - maxVisibleRecord + 1;
        }
        chart.resetChartVisibleRecord();
        chart.checkChartLastVisibleIndex();
        chart.calcChartIndicator();
        chart.invalidate();
    }

    /*
    * 触摸事件
    */
    public void callTouchEvent(String eventName, Object sender, FCTouchInfo touchInfo, Object invoke)
    {
        FCView view = (FCView)sender;
        if (view.getName().indexOf("cycle,") == 0)
        {
            String[] strs = view.getName().split("[,]");
            int index = FCTran.strToInt(strs[1]);
            int cycleInt = FCTran.strToInt(strs[2]);
            FCView myChart = m_findMyCharts.get(index);
            m_myChartsMap.get(myChart).put("cycle", FCTran.intToStr(cycleInt));
            queryHistoryData(myChart, m_charts.get(index), m_charts.get(index).getText().split("[ ]")[0]);
        }
    }

    /*
    * 单元格点击事件
    */
    public void callGridCellTouchEvent(String eventName, Object sender, FCGridCell cell, FCTouchInfo touchInfo, Object invoke)
    {
        String code = cell.getRow().getCell("colP1").getString();
        String name = cell.getRow().getCell("colP2").getString();
        for (int i = 0; i < m_findMyCharts.size(); i++)
        {
            FCView myChart = m_findMyCharts.get(i);
            String vName = myChart.getName();
            if (vName.equals("mainChart1") || vName.equals("mainChart2") || vName.equals("mainChart3"))
            {
                FCChart chart = m_charts.get(i);
                chart.setText(code + " " + name);
                queryHistoryData(myChart, chart, code);
            }
        }
        queryNewData(code);
        getNative().invalidate();
    }
}
